package 
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	
	import fl.controls.ComboBox;
	import fl.data.DataProvider;
	import fl.events.ComponentEvent;
	
	
	public class ExamOne extends MovieClip
	{
		private var isSave:Boolean = false;
		
		private var txtArr:Array;
		
		public function ExamOne()
		{
			lieBiaoControl();
			
			LieBiao1.addEventListener(MouseEvent.CLICK, onLieBiao);
			LieBiao2.addEventListener(MouseEvent.CLICK, onLieBiao);
			LiuChengZaiZao.addEventListener(MouseEvent.CLICK, onShowLieBiao2);
			DiYaXinZhuang.addEventListener(MouseEvent.CLICK, onShowPanel);
			ShenQing.addEventListener(MouseEvent.CLICK, onShowLieBiao1);
			notice.visible = false;
		}
		
		public function getScroe():Object
		{
			var scroe:int = 0;
			for(var i:int = 0;i< ExamOneData.getTxtScroeArr.length;i++)
			{
				var text:String = this["txt" + ExamOneData.getTxtScroeArr[i]].text;
				if(text == ExamOneData.txtAnswerArr[i])
				{
					scroe++;
				}
			}
			for(var i:int = 0;i<ExamOneData.getCombScroeArr.length;i++)
			{
				var comb:ComboBox = this["cb" + ExamOneData.getCombScroeArr[i]];
				if(comb.selectedLabel == ExamOneData.combAnswerArr[i])
				{
					scroe++;
				}
			}
			
//			this.dispatchEvent(new ProEvent(ProEvent.SEND_SCORE, {id:1, score:scroe}));
			trace("id:1, scroe:" + scroe);
			return {id:1, scroe:scroe};
		}
		
		private function onLieBiao(e:MouseEvent):void
		{
			lieBiaoControl();
		}
		
		private function onShowLieBiao1(e:MouseEvent):void
		{
			LieBiao1.visible = true;
			LieBiao2.visible = false;
			LiuChengZaiZao.visible = true;
			DiYaXinZhuang.visible = false;
		}
		
		private function onShowLieBiao2(e:MouseEvent):void
		{
			lieBiaoControl(true);
		}
		
		private function onShowPanel(e:MouseEvent):void
		{
			lieBiaoControl();
			setFrame(2);
			setFrame2Data();
		}
		
		private function lieBiaoControl(b:Boolean = false):void
		{
			LieBiao1.visible = b;
			LieBiao2.visible = b;
			LiuChengZaiZao.visible = b;
			DiYaXinZhuang.visible = b;
		}
		
		private function addFrame1Event():void
		{
			LieBiao1.addEventListener(MouseEvent.CLICK, onLieBiao);
			LieBiao2.addEventListener(MouseEvent.CLICK, onLieBiao);
			LiuChengZaiZao.addEventListener(MouseEvent.CLICK, onShowLieBiao2);
			DiYaXinZhuang.addEventListener(MouseEvent.CLICK, onShowPanel);
			ShenQing.addEventListener(MouseEvent.CLICK, onShowLieBiao1);
		}
		
		private function clearFrame1Event():void
		{
			LieBiao1.removeEventListener(MouseEvent.CLICK, onLieBiao);
			LieBiao2.removeEventListener(MouseEvent.CLICK, onLieBiao);
			LiuChengZaiZao.removeEventListener(MouseEvent.CLICK, onShowLieBiao2);
			DiYaXinZhuang.removeEventListener(MouseEvent.CLICK, onShowPanel);
			ShenQing.removeEventListener(MouseEvent.CLICK, onShowLieBiao1);
		}
		
		private function addFrame2Event():void
		{
			BaoCun.addEventListener(MouseEvent.CLICK, onSave);
			TongZhi.addEventListener(MouseEvent.CLICK, onTongZhi);
			QiTa.addEventListener(MouseEvent.CLICK, onQiTa);
			HuoYueDu.addEventListener(MouseEvent.CLICK, onHuoYueDu);
			LuRu.addEventListener(MouseEvent.CLICK, onLuRu);
			DanBao.addEventListener(MouseEvent.CLICK, onDanBao);
			SheBei.addEventListener(MouseEvent.CLICK, onSheBei);
			cb1.addEventListener(Event.CHANGE, onSelect);
			PianHaoPanel.visible = false;
			DaYin.addEventListener(MouseEvent.CLICK, onDaYin);
			HuiZhi.addEventListener(MouseEvent.CLICK, onHuiZhi);
			KuoZhan.addEventListener(MouseEvent.CLICK, onKuoZhan);
			ZiLiao.addEventListener(MouseEvent.CLICK, onZiLiao);
//			GuanXi.addEventListener(MouseEvent.CLICK, onGuanXi);
			
			BianGeng.addEventListener(MouseEvent.CLICK, onBianGeng);
			BanLi.addEventListener(MouseEvent.CLICK, onBanLi);
			FuJian.addEventListener(MouseEvent.CLICK, onFuJian);
			PingZheng.addEventListener(MouseEvent.CLICK, onPingZheng);

			
			
		}
		
		private function clearFrame2Event():void
		{
			BaoCun.removeEventListener(MouseEvent.CLICK, onSave);
			TongZhi.removeEventListener(MouseEvent.CLICK, onTongZhi);
			QiTa.removeEventListener(MouseEvent.CLICK, onQiTa);
			HuoYueDu.removeEventListener(MouseEvent.CLICK, onHuoYueDu);
			LuRu.removeEventListener(MouseEvent.CLICK, onLuRu);
			DanBao.removeEventListener(MouseEvent.CLICK, onDanBao);
			SheBei.removeEventListener(MouseEvent.CLICK, onSheBei);
			cb1.removeEventListener(Event.CHANGE, onSelect);
			PianHaoPanel.visible = false;
			
			DaYin.removeEventListener(MouseEvent.CLICK, onDaYin);
			HuiZhi.removeEventListener(MouseEvent.CLICK, onHuiZhi);
			KuoZhan.removeEventListener(MouseEvent.CLICK, onKuoZhan);
			ZiLiao.removeEventListener(MouseEvent.CLICK, onZiLiao);
//			GuanXi.removeEventListener(MouseEvent.CLICK, onGuanXi);
			
			BianGeng.removeEventListener(MouseEvent.CLICK, onBianGeng);
			BanLi.removeEventListener(MouseEvent.CLICK, onBanLi);
			FuJian.removeEventListener(MouseEvent.CLICK, onFuJian);
			PingZheng.removeEventListener(MouseEvent.CLICK, onPingZheng);
		}
		
		private function onDaYin(e:MouseEvent):void
		{
			DaYinP.visible = true;
			//			PianHaoPanel.gotoAndStop(frame);
			if(DaYinP.Close != null)
			{
				DaYinP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
			}
			else
			{
				trace("DaYin.Close is null");
			}
		}
		
		private function onHuiZhi(e:MouseEvent):void
		{
			HuiZhiP.visible = true;
			//			PianHaoPanel.gotoAndStop(frame);
			if(HuiZhiP.Close != null)
			{
				HuiZhiP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
			}
			else
			{
				trace("HuiZhi.Close is null");
			}
		}
		
		private function onKuoZhan(e:MouseEvent):void
		{
			KuoZhanP.visible = true;
			//			PianHaoPanel.gotoAndStop(frame);
			if(KuoZhanP.Close != null)
			{
				KuoZhanP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
			}
			else
			{
				trace("KuoZhan.Close is null");
			}
		}
		
		private function onZiLiao(e:MouseEvent):void
		{
			ZiLiaoP.visible = true;
			//			PianHaoPanel.gotoAndStop(frame);
			if(ZiLiaoP.Close != null)
			{
				ZiLiaoP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
			}
			else
			{
				trace("ZiLiao.Close is null");
			}
		}
		
//		private function onGuanXi(e:MouseEvent):void
//		{
//			showPanel(1);
//		}
		
		private function onBianGeng(e:MouseEvent):void
		{
			BianGengP.visible = true;
			//			PianHaoPanel.gotoAndStop(frame);
			if(BianGengP.Close != null)
			{
				BianGengP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
			}
			else
			{
				trace("BianGeng.Close is null");
			}
		}
		
		private function onBanLi(e:MouseEvent):void
		{
			BanLiP.visible = true;
			//			PianHaoPanel.gotoAndStop(frame);
			if(BanLiP.Close != null)
			{
				BanLiP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
			}
			else
			{
				trace("BanLi.Close is null");
			}
		}
		
		private function onFuJian(e:MouseEvent):void
		{
			FuJianP.visible = true;
			//			PianHaoPanel.gotoAndStop(frame);
			if(FuJianP.Close != null)
			{
				FuJianP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
			}
			else
			{
				trace("FuJian.Close is null");
			}
		}
		
		private function onPingZheng(e:MouseEvent):void
		{
			PingZhengP.visible = true;
			//			PianHaoPanel.gotoAndStop(frame);
			if(PingZhengP.Close != null)
			{
				PingZhengP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
			}
			else
			{
				trace("PingZheng.Close is null");
			}
		}
		
		private function onSelect(e:Event):void
		{
			trace("cb1.selectedIndex:"+cb1.selectedIndex);
			cb2.dataProvider = new DataProvider(ExamOneData.cb2[cb1.selectedIndex]);
		}
		
		private function onTongZhi(e:MouseEvent):void
		{
			if(isSave)
			{
				TongZhiP.visible = true;
				//			PianHaoPanel.gotoAndStop(frame);
				if(TongZhiP.Close != null)
				{
					TongZhiP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
				}
				else
				{
					trace("TongZhi.Close is null");
				}
			}
			else
			{
				trace("tongzhi");
				this.dispatchEvent(new ProEvent(ProEvent.SEND_NOTICE, {str:"请保存后再进行此操作！"}));
			}
		}
		
		private function onSheBei(e:MouseEvent):void
		{
			if(isSave)
			{
				SheBeiP.visible = true;
				//			PianHaoPanel.gotoAndStop(frame);
				if(SheBeiP.Close != null)
				{
					SheBeiP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
				}
				else
				{
					trace("SheBei.Close is null");
				}
			}
			else
			{
				trace("shebei");
				this.dispatchEvent(new ProEvent(ProEvent.SEND_NOTICE, {str:"请保存后再进行此操作！"}));
			}
		}
		
		private function onDanBao(e:MouseEvent):void
		{
			if(isSave)
			{
				DanBaoP.visible = true;
				//			PianHaoPanel.gotoAndStop(frame);
				if(DanBaoP.Close != null)
				{
					DanBaoP.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
				}
				else
				{
					trace("DanBao.Close is null");
				}
			}
			else
			{
				trace("danbao");
				this.dispatchEvent(new ProEvent(ProEvent.SEND_NOTICE, {str:"请保存后再进行此操作！"}));
			}
		}
		
		private function onLuRu(e:MouseEvent):void
		{
			if(isSave)
			{
				//showPanel(4);
			}
			else
			{
				trace("luru");
				this.dispatchEvent(new ProEvent(ProEvent.SEND_NOTICE, {str:"请保存后再进行此操作！"}));
			}
		}
		
		private function onHuoYueDu(e:MouseEvent):void
		{
			showPanel(1);
		}
		
		private function showPanel(frame:int):void
		{
			PianHaoPanel.visible = true;
//			PianHaoPanel.gotoAndStop(frame);
			if(PianHaoPanel.Close != null)
			{
				PianHaoPanel.Close.addEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
			}
			else
			{
				trace("PianHaoPanel.Close is null");
			}
		}
		
		private function onPianHaoPanelClose(e:MouseEvent):void
		{
			var dis:DisplayObject = e.currentTarget as DisplayObject;
			dis.parent.visible = false;
			dis.removeEventListener(MouseEvent.CLICK, onPianHaoPanelClose);
		}
		
		private function onQiTa(e:MouseEvent):void
		{
			if(isSave)
			{
				
			}
			else
			{
				this.dispatchEvent(new ProEvent(ProEvent.SEND_SCORE, {str:"请保存后再进行此操作！"}));
			}
		}
		
		private function onSave(e:MouseEvent):void
		{
			var isOk:Boolean = true;
			for(var i:int = 3;i< 32;i++)
			{
				if(this["txt" + i].text == "")
				{
					isOk = false;
					break;
				}
			}
			if(isOk)
			{
//				this.dispatchEvent(new ProEvent(ProEvent.SEND_SCORE, {id:1, score:20}));
				BianGeng.visible = true;
				BanLi.visible = true;
				FuJian.visible = true;
				PingZheng.visible = true;
				
				isSave = true;
				txt1.text = "2011307260050";
				txt2.text = "1301097038";
			}
			else
			{
				trace("send 1");
				this.dispatchEvent(new ProEvent(ProEvent.SEND_NOTICE, {str:"请将重要信息填写完整再保存!"}));
			}
//			setFrame(1);
//			lieBiaoControl();
		}
		
		private function onNoticeClose(e:MouseEvent):void
		{
			notice.visible = false;
			notice.Close.removeEventListener(MouseEvent.CLICK, onNoticeClose);
			notice.OK.removeEventListener(MouseEvent.CLICK, onNoticeClose);
		}
		
		private function setFrame(frame:int):void
		{
			this["clearFrame" + currentFrame + "Event"]();
			gotoAndStop(frame);
			this["addFrame" + frame + "Event"]();
		}
		
		private function setFrame2Data():void
		{
//			var cb:ComboBox = new ComboBox();
//			cb.dataProvider = new DataProvider(ExamOneData.cb1);
//			cb.addEventListener(ComponentEvent.SHOW, onSelect);
			cb1.dataProvider = new DataProvider(ExamOneData.cb1);
			cb1.selectedIndex = 0;
			cb2.dataProvider = new DataProvider(ExamOneData.cb2[cb1.selectedIndex]);
			cb3.dataProvider = new DataProvider(ExamOneData.cb3);
			cb4.dataProvider = new DataProvider(ExamOneData.cb4);
			cb6.dataProvider = new DataProvider(ExamOneData.cb6);
			cb7.dataProvider = new DataProvider(ExamOneData.cb7);
			cb8.dataProvider = new DataProvider(ExamOneData.cb8);
			cb9.dataProvider = new DataProvider(ExamOneData.cb9);
			cb10.dataProvider = new DataProvider(ExamOneData.cb10);
			cb11.dataProvider = new DataProvider(ExamOneData.cb11);
			cb12.dataProvider = new DataProvider(ExamOneData.cb12);
			cb13.dataProvider = new DataProvider(ExamOneData.cb13);
			cb14.dataProvider = new DataProvider(ExamOneData.cb14);
			cb15.dataProvider = new DataProvider(ExamOneData.cb15);
			cb16.dataProvider = new DataProvider(ExamOneData.cb16);
			cb17.dataProvider = new DataProvider(ExamOneData.cb17);
			cb18.dataProvider = new DataProvider(ExamOneData.cb18);
			cb19.dataProvider = new DataProvider(ExamOneData.cb19);
			cb20.dataProvider = new DataProvider(ExamOneData.cb20);
			cb21.dataProvider = new DataProvider(ExamOneData.cb21);
			cb22.dataProvider = new DataProvider(ExamOneData.cb22);
			cb23.dataProvider = new DataProvider(ExamOneData.cb23);
			cb24.dataProvider = new DataProvider(ExamOneData.cb24);
			cb25.dataProvider = new DataProvider(ExamOneData.cb25);
			cb26.dataProvider = new DataProvider(ExamOneData.cb26);
			cb27.dataProvider = new DataProvider(ExamOneData.cb27);
			cb28.dataProvider = new DataProvider(ExamOneData.cb28);
			cb29.dataProvider = new DataProvider(ExamOneData.cb29);
			cb30.dataProvider = new DataProvider(ExamOneData.cb30);
			cb31.dataProvider = new DataProvider(ExamOneData.cb31);
			
			txt10.displayAsPassword = true;
		}
	}
}